﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Waiter.Common;
using DevComponents.DotNetBar.Controls;
using Waiter.DataLayer;

namespace Waiter.Controler
{
    class HoursWork
    {
        /// <summary>
        /// Load danh sách nhân viên để chấm công
        /// </summary>
        /// <param name="pWorkShiftCode">Code ca làm việc</param>
        /// <returns></returns>
        public List<VIEW_WorkShiftToGrid> fsGetStaffGridData(string pWorkShiftCode)
        {
            try
            {
                List<VIEW_WorkShiftToGrid> resultList = (from   wsm in CommonGlobalVariable.globalDataContext.WORK_SHIFTs
                                                         join   wsd in CommonGlobalVariable.globalDataContext.WORK_SHIFTS_Ds on wsm.CODE equals wsd.WORK_SHIFTS_CODE
                                                         join   stf in CommonGlobalVariable.globalDataContext.STAFFs on wsd.STAFF_CODE equals stf.CODE
                                                         where  wsm.CODE == pWorkShiftCode & stf.DEL_FLG == false
                                                         select new VIEW_WorkShiftToGrid
                                                         {
                                                             strStaffCode = stf.CODE,
                                                             strStaffName = stf.NAME,
                                                             bDelFlag = wsd.DEL_FLG
                                                         }).OrderByDescending(x=>x.bDelFlag).ThenBy(y=>y.strStaffName).ToList();

                return resultList;

            }
            catch (Exception ex)
            {
                CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_ERROR,
                    "HoursWork.fsGetStaffGridData",
                    CommonUtils.fsParamListToString(new object[1] { pWorkShiftCode }),
                    ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// Load danh sách nhân viên đã được chấm công
        /// </summary>
        /// <param name="pWorkShiftCode">Code ca làm việc</param>
        /// <param name="pDateKeeping">Ngày chấm công</param>
        /// <returns></returns>
        public List<HOURS_WORKED> fsGetHoursWorkedGridData(string pWorkShiftCode, DateTime pDateKeeping)
        {
            try
            {
                List<HOURS_WORKED> resultList = CommonGlobalVariable.globalDataContext.HOURS_WORKEDs.OrderBy(x => x.STAFF).ToList();

                return resultList;
            }
            catch (Exception ex)
            {
                CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_ERROR,
                    "HoursWork.fsGetHoursWorkedGridData",
                    CommonUtils.fsParamListToString(new object[2] { pWorkShiftCode, pDateKeeping }),
                    ex.ToString());
                return null;
            }
        }
    }
}
